package com.foo.servicesCall;

import java.rmi.RemoteException;

import org.apache.axis2.AxisFault;

import restaurant.RestaurantClient;

import com.foo.servicesCall.GetAllMovieDataFaultException;
import com.foo.servicesCall.MovieServiceStub.GetAllMovieData;
import com.foo.servicesCall.MovieServiceStub.GetAllMovieDataResponse;
import com.foo.servicesCall.MovieServiceStub.GetMovieByGenre;
import com.foo.servicesCall.MovieServiceStub.GetMovieByGenreResponse;
import com.foo.servicesCall.MovieServiceStub.GetMovieByName;
import com.foo.servicesCall.MovieServiceStub.GetMovieByNameResponse;
import com.foo.servicesCall.MovieServiceStub.GetMovieByTheatre;
import com.foo.servicesCall.MovieServiceStub.GetMovieByTheatreResponse;
import com.foo.servicesCall.MovieServiceStub.GetMovieByTime;
import com.foo.servicesCall.MovieServiceStub.GetMovieByTimeResponse;
import com.foo.servicesCall.MovieServiceStub.GetMovieByType;
import com.foo.servicesCall.MovieServiceStub.GetMovieByTypeResponse;
import com.foo.servicesCall.MovieServiceStub.MovieData;
import com.foo.servicesCall.MovieServiceStub.MovieList;

import com.foo.servicesCall.GetAllMovieDataFaultException;


public class MovieWSClient 
{
	private static final String SERVICE_END_POINT = "http://localhost:8080/axis2/services/MovieService";
	
	private MovieServiceStub stub;
	
	public MovieWSClient()
	{
		try
		{
			stub = new MovieServiceStub(SERVICE_END_POINT);
		} catch (AxisFault e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public MovieData getMovieInfoByName(String name)
	{
		try
		{
			GetMovieByNameResponse result = null;
			GetMovieByName res = new GetMovieByName();
			res.setIn(name);
			
			try
			{
				result = stub.getMovieByName(res);
			}
			catch(RemoteException e)
			{
				System.out.println(e.getMessage());
			}
			catch(GetMovieByNameFaultException ex)
			{
				System.out.println(ex.getMessage());
			}
			
			if(result != null && result.getOut() != null)
			{
				System.out.println("Movie Details for Name Love is as follows --> \n" +
					"Movie Name: " +result.getOut().getMovie_name() + 
					"Theater Location: " + result.getOut().getTheatre_name() +
					"Movie Rating: " + result.getOut().getMovie_rating());
			}
			return result.getOut();
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		return null;
	}
	
	public MovieList getAllMovieData()
	{
		try
		{
			GetAllMovieDataResponse resu = new GetAllMovieDataResponse();
			GetAllMovieData getAllMovieData = new GetAllMovieData();
			getAllMovieData.setIn("");
			try
			{
				resu = stub.getAllMovieData(getAllMovieData);
			}
			catch(RemoteException e)
			{
				System.out.println(e.getMessage());
			}
			catch(GetAllMovieDataFaultException ex)
			{
				System.out.println(ex.getMessage());
			}
			if(resu != null)
			{
				MovieData[] movie = resu.getOut().getMovieList();
				if(movie != null)
				{
					int size = resu.getOut().getMovieList().length;
					
					//movie = new Movie[size];
					for(int i=0;i<size;i++)
					{
						System.out.println("Movie Name for All is as follows --> \n" +
								"Movie Name: " +movie[i].getMovie_name());
					}
				}
				
			}
			return resu.getOut();
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		return null;	
	}
	
	public MovieList getMovieInfoByTime(String time)
	{
		try
		{
			GetMovieByTimeResponse resu = new GetMovieByTimeResponse();
			GetMovieByTime getMovieInfoByTime = new GetMovieByTime();
			getMovieInfoByTime.setIn(time);
			try
			{
				resu = stub.getMovieByTime(getMovieInfoByTime);
			}
			catch(RemoteException e)
			{
				System.out.println(e.getMessage());
			}
			catch(GetMovieByTimeFaultException ex)
			{
				System.out.println(ex.getMessage());
			}
			if(resu != null)
			{
				MovieData[] movie = resu.getOut().getMovieList();
				if(movie != null)
				{
					int size = resu.getOut().getMovieList().length;
					
					
					for(int i=0;i<size;i++)
					{
						System.out.println("Movie Name for movie by time is as follows --> \n" +
								"Movie Name: " +movie[i].getMovie_name());
					}
				}
				
			}
			return resu.getOut();
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		return null;
	}
	public MovieList getMovieInfoByType(String type)
	{
		try
		{
			GetMovieByTypeResponse resu = new GetMovieByTypeResponse();
			GetMovieByType getMovieInfoByType = new GetMovieByType();
			getMovieInfoByType.setIn(type);
			try
			{
				resu = stub.getMovieByType(getMovieInfoByType);
			}
			catch(RemoteException e)
			{
				System.out.println(e.getMessage());
			}
			catch(GetMovieByTypeFaultException ex)
			{
				System.out.println(ex.getMessage());
			}
			if(resu != null)
			{
				MovieData[] movie = resu.getOut().getMovieList();
				if(movie != null)
				{
					int size = resu.getOut().getMovieList().length;
				
					for(int i=0;i<size;i++)
					{
						System.out.println("Movie Name for movie by time is as follows --> \n" +
								"Movie Name: " +movie[i].getMovie_name());
					}
				}
				
			}
			return resu.getOut();
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		return null;
	}
	public MovieList getMovieInfoByGenre(String genre)
	{
		try
		{
			GetMovieByGenreResponse resu = new GetMovieByGenreResponse();
			GetMovieByGenre getMovieInfoByGenre = new GetMovieByGenre();
			getMovieInfoByGenre.setIn(genre);
			try
			{
				resu = stub.getMovieByGenre(getMovieInfoByGenre);
			}
			catch(RemoteException e)
			{
				System.out.println(e.getMessage());
			}
			catch(GetMovieByGenreFaultException ex)
			{
				System.out.println(ex.getMessage());
			}
			if(resu != null)
			{
				MovieData[] movie = resu.getOut().getMovieList();
				if(movie != null)
				{
					int size = resu.getOut().getMovieList().length;
					
					for(int i=0;i<size;i++)
					{
						System.out.println("Movie Name for movie by time is as follows --> \n" +
								"Movie Name: " +movie[i].getMovie_name());
					}
				}
				
			}
			return resu.getOut();
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		return null;
	}
	
	public MovieList getMovieInfoByTheatre(String theatre)
	{
		try
		{
			GetMovieByTheatreResponse resu = new GetMovieByTheatreResponse();
			GetMovieByTheatre getMovieInfoByTheatre = new GetMovieByTheatre();
			getMovieInfoByTheatre.setIn(theatre);
			try
			{
				resu = stub.getMovieByTheatre(getMovieInfoByTheatre);
			}
			catch(RemoteException e)
			{
				System.out.println(e.getMessage());
			}
			catch(GetMovieByTheatreFaultException ex)
			{
				System.out.println(ex.getMessage());
			}
			if(resu != null)
			{
				MovieData[] movie = resu.getOut().getMovieList();
				if(movie != null)
				{
					int size = resu.getOut().getMovieList().length;
					
					for(int i=0;i<size;i++)
					{
						System.out.println("Movie Name for movie by time is as follows --> \n" +
								"Movie Name: " +movie[i].getMovie_name());
					}
				}
				
			}
			return resu.getOut();
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		return null;
	}
	
public static void main(String[] args) {		
		MovieWSClient client = new MovieWSClient();
		client.getAllMovieData();
	}

	
}
